package source.model;

import source.events.action.MoveDirection;
import source.model.type.ActionResult;
import source.model.type.GameObjectType;
import source.model.type.ItemType;
import source.events.action.*;
import source.view.*;

public class CosmicDrill extends Item implements Useable{

	public CosmicDrill(){
		super(ItemType.COSMICDRILL);
	}
	
	public Action use(){
		return new Action(){
			public ActionResult execute(DataHandler dh){
				Unit executor=(Unit)dh.getCurrentSelection();
				MoveDirection facing=executor.getFacing();
				Position executorPosition=dh.positionQuery(executor.objectID());
				Position notP=new Position(executorPosition.getX()+facing.xChange(), executorPosition.getY()+facing.yChange());
				GameObject[] temp=dh.positionQuery(notP, GameObjectType.ITEM);
				Item item=(Item)temp[0];
				MainScreen.writeToConsole(""+item);
				if(item==null||!item.getItemType().equals(ItemType.COMET))
					return ActionResult.IMPOSSIBLE;
				Player player=dh.getPlayer(dh.playerIDQuery(executor.objectID()));
				MainScreen.writeToConsole("Bonus Ore!");
				player.incrementOre(500);
				return ActionResult.SUCCESS;
			}
		};
	}
}
